<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-button @click="addNewRecord" type="primary">添加重点驾驶员</el-button>
                <el-input style="width:200px" v-model="filters.keyDriverName" placeholder="请输入驾驶员姓名"></el-input>
                <el-input style="width:200px" v-model="filters.certifID" placeholder="请输入驾驶员身份证"></el-input>
                <el-button type="primary" icon="search" @click="getKeyDrivers">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list">
                          <el-table-column v-for="(v,k,i) in props" :key="i" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span v-if="k==='sex'">
                                       {{scope.row[k]==1?'男':'女'}}
                                  </span>
                                  <span v-else>
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <el-button type="text" @click="ckDetail(scope.row.keyDriverID)">查看详情</el-button>
                                  <el-button type="text" @click="editDrivers(scope.row.keyDriverID)">编辑</el-button>
                                  <el-button type="text" @click="deleteDrivers(scope.row.keyDriverID)">删除</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                  </el-col>
                  <el-col :span="24" style="margin-top:10px" align="right">
                      <el-pagination layout="prev, pager, next" :total="totalInfo" @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>

      <el-dialog title="查看人员详细信息" :visible.sync="visible">
        <baisc-info-table :item="form" :names="label2" :hasimg="true" :imgUrl="pic"></baisc-info-table>
      </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "@/api/videoManage";
import * as api2 from "@/api/trafficManage";
import BaiscInfoTable from "../../components/InfoTemplate";
export default {
  components: {
    treeComponent: treeComponent,
    BaiscInfoTable:BaiscInfoTable
  },
  data() {
    return {
      visible:false,
      filters: {
        keyDriverName: null, //驾驶员姓名
        certifID: null, //驾驶员身份证号
        netGridID: null, // 所属网格
        page: 1,
        pageSize: 10
      },
      list: [
        {
          keyDriverID: "", //          bigint,
          keyDriverName: "", //        varchar(50),
          certifID: "", //             char(18) not null comment '身份证号. 编码应符合GB 11643',
          sex: 1, //                  char(1) comment '1=男性；0=女性，编码应符合 GB/T 2261.1',
          contact: "", //              varchar(50) comment '联系方式',
          drivingLicenseTypeValue: "", // char(2) comment '准驾车型',
          homeAddress: "", //          varchar(200) comment '家庭住址',
          netGridID: 1, //            bigint comment '常住地址所在网格',
          enterpriseUSCcode: "", //    char(18) comment '如果该驾驶员属于某个公司，则填入该公司统一社会信用代码；否则，可不填。',
          remarks: "" //              varchar(500)
        }
      ],
      totalInfo: 0,
      props: {
        keyDriverID: "", //          bigint,
        keyDriverName: "", //        varchar(50),
        certifID: "", //             char(18) not null comment '身份证号. 编码应符合GB 11643',
        sex: "", //                  char(1) comment '1=男性；0=女性，编码应符合 GB/T 2261.1',
        contact: "", //              varchar(50) comment '联系方式',
        drivingLicenseTypeName: "", // char(2) comment '准驾车型',
        homeAddress: "", //          varchar(200) comment '家庭住址',
        netGridName: "" //            bigint comment '常住地址所在网格'
      },
      labels: ["编号", "姓名", "身份证号", "性别", "联系方式", "准驾车型", "家庭住址", "所属网格"],
      label2: ["编号","姓名", "身份证号", "性别", "联系方式",'准驾车型','家庭住址',"所属网格","全国统一代码","备注"],
      form:{},
      pic:null
    };
  },
  methods: {
    deleteDrivers(id) {
      this.$confirm("是否删除此驾驶员记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api2.deleteKeyDriver(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getKeyDrivers();
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filters.keyDriverName = this.filters.certifID = null;
      this.getKeyDrivers();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getKeyDrivers();
    },
    ckDetail(id) {
      api2.fetchDetaileByDriverID(id).then(res=>{
          this.form = res.data.detail
          this.pic = res.data.pictures[0]
          this.visible = true
      })
    },
    addNewRecord() {
      this.$router.push("addKeyDriver");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getKeyDrivers();
    },
    editDrivers(id) {
      this.$router.push({ path: "editDriverInfo", query: { id: id } });
    },
    getKeyDrivers() {
      api2.fetchKeyDricerInfo(this.filters).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filters.keyDriverName = this.filters.certifID =  null;
    }
  },
  mounted() {
    if(this.$store.getters.user.userRole!='超级管理员')
      this.filters.netGridID = this.$store.getters.user.netGridID
    this.getKeyDrivers();
  }
};
</script>


<style scoped>

</style>
